package com.example.springboot.config;


import com.example.springboot.servlet.MyServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration   //配置类
public class ServletConfig {

    //@Bean 是一个方法级别上的注解，主要用在配置类里
    /*
     * 相当于一个<beans>
     * <bean id="" class=""/>
     * </beans>
     * */
    @Bean
    public ServletRegistrationBean myServletRegistrationBean() {
//将自定义 servlet 注册到注册 Servlet 类中，并指定访问路径
        ServletRegistrationBean servletRegistrationBean = new
                ServletRegistrationBean(new MyServlet(), "/springboot/myServlet");
        return servletRegistrationBean;
    }
}
